package tool

import (
	"golang.org/x/crypto/bcrypt"
)

// HashPassword 对输入的密码进行加密哈希处理
func HashPassword(password string) (string, error) {
	hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	return string(hashedPassword), nil
}

// ComparePasswords 比较哈希密码和输入密码是否匹配
func ComparePasswords(hashedPassword, inputPassword string) bool {
	return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(inputPassword)) == nil
}
